package org.spindle.soasuite.core.api;

import org.spindle.soasuite.core.constants.StateConstants;
import org.spindle.soasuite.datasource.internal.core.InternalDS;

import java.util.HashMap;
import java.util.Map;

public abstract class AExecutable {

    private Map<String, Object> stateMap;
    private Map<String, Object> returnMap;

    private String path;
    private int returnType;

    private InternalDS internalDS;

    public Object executeController() {
        returnType = -1;
        if (returnMap == null) {
            returnMap = new HashMap<String, Object>();
        } else if (returnMap.size() > 0) {
            returnMap.clear();
        }
        return execute();
    }

    public int getReturnType() {
        return returnType;
    }

    public void setReturnType(int returnType) {
        this.returnType = returnType;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public void addReturnParameter(String key, Object value) {
        returnMap.put(key, value);
    }

    public Map<String, Object> getReturnMap() {
        return returnMap;
    }

    public abstract Object execute();

    public abstract String getName();

    public void setStateMap(Map<String, Object> stateMap) {
        this.stateMap = stateMap;
    }


    public void setStateObject(String key, Object value) {
        stateMap.put(key, value);
    }

    public Object getStateObject(String key) {
        return stateMap.get(key);
    }

    public InternalDS getInternalDatasource() {
        if (internalDS == null) {
            internalDS = (InternalDS) stateMap.get(StateConstants.INTERNAL_DS);
        }
        return internalDS;
    }

    


}
